<?php
session_start();
include_once("conf/CoreConfiguration.inc.php");
include_once("conf/CoreSetting.inc.php");

include_once(LIB_IMPORTER_PATH . DBMS_LIB_IMPORTER_NAME);
include_once(LIB_IMPORTER_PATH . CORE_LIB_IMPORTER_NAME);
include_once(LIB_IMPORTER_PATH . CORE_LIB_IMPORTER_NAME);
include_once(LIB_IMPORTER_PATH . SUPPORT_LIB_IMPORTER_NAME);
include_once(LIB_IMPORTER_PATH . TEMPLATE_LIB_IMPORTER_NAME);
include_once(LIB_IMPORTER_PATH . THEME_LIB_IMPORTER_NAME);
include_once(LIB_IMPORTER_PATH . APPLICATION_CORE_LIB_IMPORTER_NAME);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
        <title><?php echo CORE_APPLICATION ?></title>

        <?php
        foreach ($mIncStyle as $style) {
            echo $style;
        }

        foreach ($mIncJS as $jscript) {
            echo $jscript;
        }
        ?>
    </head>

    <body>
        <?php
        if (!CORE_DEVELOPING_MODE) {
            $mTheme = new ThemeBasic();
            $mTheme->PrintRedirectingPage();
        }
        ?>
    </body>	
</html>

<?
$myApp = new Application();
$myApp->SetLevelAccess(true);

$mFormRollback = new FormRecovery($_POST);
$mValidation = new InputValidation();
$mFunction = new Fungsi();


$mAct = 'edt';

//SETUP USER
$mUser= new CoreUser($_SESSION[User][Id]);

//SETUP PASSWORD
$mValidation->SetInput($_POST['fPassword']);
$mValidation->SetPattern(pPass);
$tPassword = $mValidation->CheckValidation();

$mValidation->SetInput($_POST['fRePassword']);
$mValidation->SetPattern(pPass);
$tRePassword = $mValidation->CheckValidation();
////
//$tGoto= "main.php?menu=11&submenu=111";
if ($tPassword && $tPassword === $tRePassword) {
    //SETUP LOGGED
    $mLogged = new Logged();
    $mLogged->SetUsername($_SESSION['User']['Username']);
    $mLogged->SetPassword($tPassword);
    ////
    $tSalt = $mLogged->GenerateSalt();
    $tPwdHash = $mLogged->GeneratePasswordHash($tSalt);

    $mFunction->SetVariableToMultiFormVariableSupport('fPersonId', $_SESSION['User']['Id'], false, false);
    $mFunction->SetVariableToMultiFormVariableSupport('fCurrentPKValue', $_SESSION['User']['Id'], false, false);
    $mFunction->SetVariableToMultiFormVariableSupport('fPasswordHash', $tPwdHash, false, false);
    $mFunction->SetVariableToMultiFormVariableSupport('fLoginLast', date("Y-m-d"), false, false);
    $mFunction->SetVariableToMultiFormVariableSupport('fStatus', 1, false, false);
    $mFunction->SetVariableToMultiFormVariableSupport('fSalt', $tSalt, false, false);

    $mData = new DBQueryExecute();
    $mData->SetTargerURL("main.php");

    //SETUP Nama Tabel
    $mData->SetTableName("app_user");
    $mData->SetMultiForm(false);

    $mData->SetPrimaryKey('person_id', 'fPersonId', pUserId);
    $mData->SetField('pwd', 'fPasswordHash', pPass);
    $mData->SetField('login_l', 'fLoginLast', pDateDB);
    $mData->SetField('status', 'fStatus', pUnsignedInt);
    $mData->SetField('salt', 'fSalt', pUnsignedInt);

    $mData->SetValiditas($mUser->GetLevel() . "|" . $mUser->GetUsername() . "|" . $mUser->GetUserId() . "|" . $tSalt);

    if (!$mData->GetError())
        $tResult = $mData->ExecuteQuery($mAct);
} else {
    if (!$mAct && $_POST['act']) {
        // ERROR: aksi tidak diketahui. kemungkinan diubah oleh user
    } else {
        // ERROR: nilai aksi tidak didefinisikan
        echo 'pasword tidak sama';
    }
}
?>




